// 若要新增模块，请使用命名空间
// 建议通过mapState、mapActions、mapGatters钩子引入
// setup组件内使用store，需要 import { useStore } from 'vuex'


import { createStore, createLogger } from 'vuex'
import { toRaw } from '@vue/reactivity'
import app from './modules/app'
import user from './modules/user'
import permission from './modules/permission'
import createPersistedState from 'vuex-persistedstate'

export default createStore({
  state: {},
  mutations: {},
  actions: {},
  getters: {
    sidebar: (state: any) => toRaw(state.app.sidebar),
    device: (state: any) => toRaw(state.app.device),
    token: (state: any) => toRaw(state.user.token),
    avatar: (state: any) => toRaw(state.user.avatar),
    name: (state: any) => toRaw(state.user.name),
    status: (state: any) => toRaw(state.user.status),
    roles: (state: any) => toRaw(state.user.roles),
    user_id: (state: any) => toRaw(state.user.id),
    tenant_id: (state: any) => toRaw(state.user.tenantId),
    permission_routers: (state: any) => toRaw(state.permission.routers),
    addRouters: (state: any) => toRaw(state.permission.addRouters)
    // devices: (state) => state.devices.devices,
    // energyType: (state) => state.energyType.energyType,
    // virtualTable: (state) => state.virtualTable.virtualTable,
    // flatEnergyType: (state) => state.energyType.flatEnergyType
  },
  modules: {
    app,
    user,
    permission
  },
  plugins: [
    createPersistedState({
      key: 'abc', // erabbit-client-pc-store
      paths: ['user', 'cart']
    }), //这部分是做持久化的
    createLogger() // 这个是logger模块
  ]
})
